package com.shelpe.services.sinbad.controller.actionLog.impl.adgroup;

import java.util.Locale;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Service;

import com.shelpe.services.sinbad.controller.actionLog.ActionLogDto;
import com.shelpe.services.sinbad.controller.actionLog.ActionLogService;
import com.shelpe.services.sinbad.entity.jpa.Adgroup;
import com.shelpe.services.sinbad.entity.jpa.AdgroupLog;
import com.shelpe.services.sinbad.entity.jpa.Campaign;

@Service
public class AdgroupAddConverter extends ActionLogService {
	@Autowired
	private MessageSource messageSource;

	@Override
	public ActionLogDto convertAdgroup(AdgroupLog entity, Map<Long, Campaign> campaignMap,
			Map<Long, Adgroup> adgroupMap) {
		boolean adgroupAddConverter = entity.getAction() == AdgroupLog.Action.AUTO_ADD
				|| entity.getAction() == AdgroupLog.Action.MANUAL_ADD;
		if (adgroupAddConverter) {
			Adgroup adgroup = adgroupMap.get(entity.getAdgroupID());
			if (adgroup != null) {
				ActionLogDto dto = new ActionLogDto();
				dto.from(entity);
				String[] params = { adgroup.getProductName(), (float) adgroup.getDefaultPrice() / 100 + "" };
				dto.setReason(messageSource.getMessage("message.adgroup.add.reason", params, Locale.ENGLISH));
				return dto;
			}
		}
		return null;
	}
}
